<?php

namespace app\index\controller;

use think\Controller;
use think\Request;

class GiftLog extends Controller
{

    protected $giftLogM;
    protected $userM;
    protected $giftM;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->giftLogM = new \app\index\model\GiftLog();
        $this->userM = new \app\index\model\User();
        $this->giftM = new \app\index\model\Gift();
    }

    /**
     * 礼物流水列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $key = input('get.key');
        if ($key){
            $info =  input('get.info');
            if ($key == 'uid' || $key == 'from_uid'){
                $userid = $this->userM->where(['nickname'=>['like','%'.$info.'%']])->column('id');
                $where[$key] = ['in',$userid];
            }
            if ( $key == 'gift_id'){
                $giftid = $this->giftM->where(['name'=>['like','%'.$info.'%']])->column('id');
                $where[$key] = ['in',$giftid];
            }
        }else{
            $info = '';
            $where = '';
        }
        $list = $this->giftLogM->where($where)->paginate(10);
        $this->assign('key', ['key'=>$key,'info'=>$info]);
        $this->assign('data', $list);
        return $this->fetch('');
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
